#include "StdAfx.h"
#include "sh_octree.h"

sh_octree::sh_octree( int max_cells_allowed )
: m_nodes(NULL)
{
    stb_arr_setsize(m_nodes, max_cells_allowed);
    clear();
}

sh_octree::~sh_octree()
{
    stb_arr_free(m_nodes);
}

bool sh_octree::subdivide( stb_uint16 node )
{
    if (stb_arr_valid(m_nodes, m_cur_nodes + 8))
    {
        return false;
    }

    m_nodes[node].set_child(m_cur_nodes);
    m_cur_nodes += 8;

    return true;
}

void sh_octree::set_data( stb_uint16 node )
{
    sh_node& cur_node = m_nodes[node];
    //assert(cur_node.is_leaf());

}

void sh_octree::clear()
{
    memset(m_nodes, 0xFF, stb_arrhead(m_nodes)->limit*sizeof(sh_node));
    m_cur_nodes = 1;
}
